#include <stdio.h>

void Swap(int* p1, int* p2);
void Bubble_Sort(int* arr, int n);
void SelectSort(int* arr, int n);

int main()
{

	int arr[] = { 1,4,3,2,6,5,0,9,8 };
	SelectSort(arr, sizeof(arr) / sizeof(arr[0]));

	for (int i = 0; i < 9; i++)
	{
		printf("%d ", arr[i]);
	}

	return 0;
}

void SelectSort(int* arr, int n)
{
	int left = 0;
	int right = n - 1;

	while (left < right)
	{
		int max = left;
		int min = left;

		for (int i = left + 1; i <= right; i++)
		{
			if (arr[max] < arr[i])
			{
				max = i;
			}

			if (arr[min] > arr[i])
			{
				min = i;
			}
		}

		Swap(&arr[max], &arr[right]);

		if (min == right)
		{
			min = max;
		}

		Swap(&arr[min], &arr[left]);

		left++;
		right--;
	}
}

void Bubble_Sort(int* arr, int n)
{

	int temp = 0;

	for (int i = 0; i < n - 1; i++)
	{
		int flag = 0;
		for (int j = 0; j < n - i - 1; j++)
		{
			if (arr[j] > arr[j + 1])
			{
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;

				flag = 1;
			}
		}
		if (flag == 0)
		{
			break;
		}
	}
}

void Swap(int* p1, int* p2)
{
	int temp = *p1;
	*p1 = *p2;
	*p2 = temp;
}